package com.cupk.rotaryguard.monitor.controller.flask;

import com.cupk.common.base.config.Contant;
import okhttp3.*;

import java.io.IOException;

/**
 * 调用flask接口实现特征工程
 *
 * @author tjy
 */
public class FlaskHttpClient {

    /**
     * 初始数据转换为时间窗数据
     *
     * @return
     * @throws IOException
     */
    public static String testCSVToTestTW() throws IOException {
        MediaType mediaType = MediaType.parse("application/json");

        RequestBody body = RequestBody.create(mediaType, "{\"path_machine\": \"/Users/tjy/GraduationDesign/rotaryGuard/rotaryGuard-monitor/src/main/resources/dataset/test\", \"out_machine\": \"/Users/tjy/GraduationDesign/rotaryGuard/rotaryGuard-monitor/src/main/resources/datatw/test\", \"tw_size\": 1024, \"step_size\": 256}");

        Request request = new Request.Builder()
                .url(Contant.TEST_CSV_TO_TEST_TW)
                .post(body)
                .addHeader("Content-Type", "application/json")
                .build();
        OkHttpClient client = new OkHttpClient();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }

    /**
     * 时间窗-gena
     *
     * @return
     * @throws IOException
     */
    public static String testTWtoTestGena() throws IOException {
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "{\n\t\"path_machine\": \"/Users/tjy/GraduationDesign/rotaryGuard/rotaryGuard-monitor/src/main/resources/datatw/test\",\n\t\"out_machine\": \"/Users/tjy/GraduationDesign/rotaryGuard/rotaryGuard-monitor/src/main/resources/datagena/testgena.csv\"\n}");
        Request request = new Request.Builder()
                .url(Contant.TEST_TW_TO_TEST_GENA)
                .post(body)
                .addHeader("Content-Type", "application/json")
                .build();
        OkHttpClient client = new OkHttpClient();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }

    /**
     * gena-all-feature
     *
     * @return
     * @throws IOException
     */
    public static String getAllFeatureCSV() throws IOException {
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
                .url(Contant.ALL_FEATURE_CSV)
                .post(body)
                .addHeader("Content-Type", "application/json")
                .build();
        OkHttpClient client = new OkHttpClient();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }

    /**
     * 选取特征
     *
     * @return
     * @throws IOException
     */
    public static String selectAllFeature() throws IOException {
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "{\n\t\"feature_test_path\": \"/Users/tjy/GraduationDesign/rotaryGuard/rotaryGuard-monitor/src/main/resources/feature/test/allfeature_test.csv\",\n\t\"feature_selected_path\": \"/Users/tjy/GraduationDesign/rotaryGuard/rotaryGuard-monitor/src/main/resources/needdiagnosiscsv/feature_all.csv\"\n}");
        Request request = new Request.Builder()
                .url(Contant.SELECT_ALL_FEATURE)
                .post(body)
                .addHeader("Content-Type", "application/json")
                .build();
        OkHttpClient client = new OkHttpClient();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }
}
